package com.congee02.dbservlet.servlet;

import com.congee02.dbservlet.framework.ioc.annotation.Autowired;
import com.congee02.dbservlet.framework.ioc.annotation.Component;
import com.congee02.dbservlet.framework.ioc.annotation.WebServlet;
import com.congee02.dbservlet.service.register.RegisterService;
import com.congee02.dbservlet.service.register.RegisterServiceImpl;
import com.congee02.dbservlet.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
@WebServlet(mappings = "/register")
public class RegisterServlet extends HttpServlet {

    @Autowired
    private RegisterServiceImpl registerService;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        String username = req.getParameter("username");
        String pwd = req.getParameter("pwd");

        ResponseUtils.writeJsonAndClose(resp, registerService.register(username, pwd));

    }

}
